﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TimetableSystem.Model;

namespace TimetableSystem.Repository
{
    /// <summary>
    /// A test repository which returns hard coded data - alter the usernames in PopulateRepository to work with different barcodes etc.
    /// </summary>
    public class TestRepository
    {
        public TestRepository()
        {
            PopulateRepository();
        }

        private void PopulateRepository()
        {
            Users = new List<User>();
            //The string passed through here represents the username which is searched for
            //e.g. matriculation number
            Users.Add(CreateDrew("1"));
            Users.Add(CreateDave("1261973"));
            Users.Add(CreateKyle("1350628"));
            Users.Add(CreateExample1stYear("2"));
            Users.Add(CreateExample2ndYear("3"));
        }

        public List<User> Users { get; set; }

        public User GetUser(string username)
        {
            if (Users == null) return null;

            for (int i = 0; i < Users.Count; i++)
            {
                if (Users[i].UserName.Equals(username))
                    return Users[i];
            }
            System.Diagnostics.Debug.WriteLine("User not found: " + username);
            return null;
        }

        #region hard coded users

        private User CreateDrew(string username)
        {
            //Create Lessons
            //Note: new DateTime(2011, 3, 28, 9, 15, 0) = 28/3/2010 9:15.00
            var internetEngLesson1 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 28, 9, 15, 0), new DateTime(2011, 3, 28, 10, 15, 0), "EM170");
            var internetEngLesson2 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 30, 9, 15, 0), new DateTime(2011, 3, 30, 10, 15, 0), "EM302");
            var internetEngLesson3 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 31, 14, 15, 0), new DateTime(2011, 3, 31, 15, 15, 0), "EM170");
            var distroParallelLesson1 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 28, 16, 15, 0), new DateTime(2011, 3, 28, 17, 15, 0), "EM303");
            var distroParallelLesson2 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 31, 9, 15, 0), new DateTime(2011, 3, 31, 10, 15, 0), "EM170");
            var distroParallelLesson3 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 31, 13, 15, 0), new DateTime(2011, 3, 31, 14, 15, 0), "EMG45");

            //Create courseworks
            var internetEngCwPart1 = new Coursework(Guid.NewGuid(), "Protocol Improvement Part 1", "", new DateTime(), new DateTime(2011, 2, 14, 16, 30, 0));
            var internetEngCwPart2 = new Coursework(Guid.NewGuid(), "Protocol Improvement Part 2", "", new DateTime(), new DateTime(2011, 2, 14, 16, 30, 0));
            var distroParallelCw = new Coursework(Guid.NewGuid(), "Evaluating Parallel Programming Models", "", new DateTime(), new DateTime(2011, 2, 18, 15, 30, 0));

            //Create exams
            var internetEngExam = new Exam(Guid.NewGuid(), new DateTime(2011, 4, 28, 14, 0, 0), new DateTime(2011, 4, 28, 16, 0, 0), "SH1");
            var distroParallelExam = new Exam(Guid.NewGuid(), new DateTime(2011, 5, 3, 9, 30, 0), new DateTime(2011, 5, 3, 11, 30, 0), "JWC2");

            //Create modules
            var internetEng = new Module(Guid.NewGuid(), 2010, Semester.SemesterTwo, "Internet Engineering", "F21IE", "");
            internetEng.Lessons = new List<Lesson>() { internetEngLesson1, internetEngLesson2, internetEngLesson3 };
            internetEng.Courseworks = new List<Coursework>() { internetEngCwPart1, internetEngCwPart2 };
            internetEng.Exams = new List<Exam>() { internetEngExam };
            var distroParalel = new Module(Guid.NewGuid(), 2010, Semester.SemesterTwo, "Distributed and Paralell Technology", "F21DP", "");
            distroParalel.Lessons = new List<Lesson>() { distroParallelLesson1, distroParallelLesson2, distroParallelLesson3 };
            distroParalel.Courseworks = new List<Coursework>() { distroParallelCw };
            distroParalel.Exams = new List<Exam>() { distroParallelExam };

            //Create user - the username is what will be used for the user recognition
            var drew = new User(Guid.NewGuid(), "Drew", "Forster", username, "Software Engineering");
            drew.Modules = new List<Module>() { internetEng, distroParalel };

            return drew;
        }

        private User CreateDave(string username)
        {
            //Create Lessons
            var compGamesLect1 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 28, 10, 15, 0), new DateTime(2011, 3, 28, 11, 15, 0), "EM244");
            var compGamesLect2 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 30, 11, 15, 0), new DateTime(2011, 3, 30, 12, 15, 0), "EM307");
            var compGamesLect3 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 31, 11, 15, 0), new DateTime(2011, 3, 31, 12, 15, 0), "EM183");
            var eCommLect1 = new Lesson(Guid.NewGuid(), new DateTime(2011, 4, 1, 10, 15, 0), new DateTime(2011, 4, 1, 11, 15, 0), "EM336");

            //Create courseworks
            var compGamesCoursework = new Coursework(Guid.NewGuid(), "Computer Games Assignment", ".", new DateTime(), new DateTime(2011, 3, 31, 14, 30, 0));
            var eCommCoursework1 = new Coursework(Guid.NewGuid(), "e-Commerce Assignment 1", "Website", new DateTime(), new DateTime(2011, 3, 31, 16, 30, 0));
            var eCommCoursework2 = new Coursework(Guid.NewGuid(), "e-Commerce Assignment 1", "Portfolio", new DateTime(), new DateTime(2011, 4, 1, 16, 30, 0));

            //Create exams
            var compGamesExam = new Exam(Guid.NewGuid(), new DateTime(2011, 4, 26, 14, 0, 0), new DateTime(2011, 4, 26, 16, 0, 0), "SH1");
            var eCommExam = new Exam(Guid.NewGuid(), new DateTime(2011, 4, 28, 9, 30, 0), new DateTime(2011, 4, 28, 11, 30, 0), "SH1");

            //Create modules
            var compGames = new Module(Guid.NewGuid(), 2010, Semester.SemesterTwo, "Computer Games Programming", "F21CGP", "T");
            compGames.Lessons = new List<Lesson>() { compGamesLect1, compGamesLect2, compGamesLect3 };
            compGames.Courseworks = new List<Coursework>() { compGamesCoursework };
            compGames.Exams = new List<Exam>() { compGamesExam };
            var eComm = new Module(Guid.NewGuid(), 2010, Semester.SemesterTwo, "e-Commerce Technology", "F21ET", "");
            eComm.Lessons = new List<Lesson>() { eCommLect1 };
            eComm.Courseworks = new List<Coursework>() { eCommCoursework1, eCommCoursework2 };
            eComm.Exams = new List<Exam>() { eCommExam };

            //Create user - the username is what will be used for the user recognition
            var dave = new User(Guid.NewGuid(), "Dave", "Dunsmore", username, "Software Engineering");
            dave.Modules = new List<Module>() { compGames, eComm };

            return dave;
        }

        private User CreateKyle(string username)
        {
            //Create Lessons
            //Note: new DateTime(2011, 3, 28, 9, 15, 0) = 28/3/2010 9:15.00
            var eCommLect1 = new Lesson(Guid.NewGuid(), new DateTime(2011, 4, 1, 10, 15, 0), new DateTime(2011, 4, 1, 11, 15, 0), "EM336");
            var distroParallelLesson1 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 28, 16, 15, 0), new DateTime(2011, 3, 28, 17, 15, 0), "EM303");
            var distroParallelLesson2 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 31, 9, 15, 0), new DateTime(2011, 3, 31, 10, 15, 0), "EM170");
            var distroParallelLesson3 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 31, 13, 15, 0), new DateTime(2011, 3, 31, 14, 15, 0), "EMG45");

            //Create courseworks
            var distroParallelCw = new Coursework(Guid.NewGuid(), "Evaluating Parallel Programming Models", "", new DateTime(), new DateTime(2011, 2, 18, 15, 30, 0));
            var eCommCoursework1 = new Coursework(Guid.NewGuid(), "e-Commerce Assignment 1", "Website", new DateTime(), new DateTime(2011, 3, 31, 16, 30, 0));
            var eCommCoursework2 = new Coursework(Guid.NewGuid(), "e-Commerce Assignment 1", "Portfolio", new DateTime(), new DateTime(2011, 4, 1, 16, 30, 0));

            //Create exams
            var eCommExam = new Exam(Guid.NewGuid(), new DateTime(2011, 4, 28, 9, 30, 0), new DateTime(2011, 4, 28, 11, 30, 0), "SH1");
            var distroParallelExam = new Exam(Guid.NewGuid(), new DateTime(2011, 5, 3, 9, 30, 0), new DateTime(2011, 5, 3, 11, 30, 0), "JWC2");

            //Create modules
            var eComm = new Module(Guid.NewGuid(), 2010, Semester.SemesterTwo, "e-Commerce Technology", "F21ET", "");
            eComm.Lessons = new List<Lesson>() { eCommLect1 };
            eComm.Courseworks = new List<Coursework>() { eCommCoursework1, eCommCoursework2 };
            eComm.Exams = new List<Exam>() { eCommExam };
            var distroParalel = new Module(Guid.NewGuid(), 2010, Semester.SemesterTwo, "Distributed and Paralell Technology", "F21DP", "");
            distroParalel.Lessons = new List<Lesson>() { distroParallelLesson1, distroParallelLesson2, distroParallelLesson3 };
            distroParalel.Courseworks = new List<Coursework>() { distroParallelCw };
            distroParalel.Exams = new List<Exam>() { distroParallelExam };

            //Create user - the username is what will be used for the user recognition
            var kyle = new User(Guid.NewGuid(), "Kyle", "McNally", username, "Software Engineering");
            kyle.Modules = new List<Module>() { eComm, distroParalel };

            return kyle;
        }

        private User CreateExample1stYear(string username)
        {
            //Create Lessons
            //Note: new DateTime(2011, 3, 28, 9, 15, 0) = 28/3/2010 9:15.00
            var introToDBSLesson1 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 28, 12, 15, 0), new DateTime(2011, 3, 28, 13, 15, 0), "LT2/EM250");
            var introToDBSLesson2 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 28, 13, 15, 0), new DateTime(2011, 3, 28, 14, 15, 0), "EM250");
            var introToDBSLesson3 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 30, 13, 15, 0), new DateTime(2011, 3, 30, 14, 15, 0), "EM244");

            var introToComputerSystemsLesson1 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 28, 15, 15, 0), new DateTime(2011, 3, 28, 17, 15, 0), "EM250");
            var introToComputerSystemsLesson2 = new Lesson(Guid.NewGuid(), new DateTime(2011, 4, 1, 13, 15, 0), new DateTime(2011, 4, 1, 15, 15, 0), "EM183");

            var technoInSocietyLesson1 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 29, 10, 15, 0), new DateTime(2011, 3, 29, 13, 15, 0), "EM307");
            var technoInSocietyLesson2 = new Lesson(Guid.NewGuid(), new DateTime(2011, 4, 1, 11, 15, 0), new DateTime(2011, 4, 1, 12, 15, 0), "EM250");

            var mgmtEnterpriseLesson1 = new Lesson(Guid.NewGuid(), new DateTime(2011, 4, 1, 9, 15, 0), new DateTime(2011, 4, 1, 11, 15, 0), "LT4");

            //Create courseworks
            var technoInSocietyCoursework1 = new Coursework(Guid.NewGuid(), "Story", "", new DateTime(), new DateTime(2011, 2, 13, 16, 0, 0));
            var technoInSocietyCoursework2 = new Coursework(Guid.NewGuid(), "Review", "", new DateTime(), new DateTime(2011, 3, 25, 16, 0, 0));
            var technoInSocietyCoursework3 = new Coursework(Guid.NewGuid(), "Presentation", "", new DateTime(), new DateTime(2011, 4, 1, 16, 0, 0));
            var introToDBSCoursework1 = new Coursework(Guid.NewGuid(), "Coursework 1", "", new DateTime(), new DateTime(2011, 2, 18, 16, 0, 0));
            var introToDBSCoursework2 = new Coursework(Guid.NewGuid(), "Coursework 2", "", new DateTime(), new DateTime(2011, 3, 25, 16, 0, 0));

            //Create exams
            var introToDBSExam = new Exam(Guid.NewGuid(), new DateTime(2011, 5, 18, 14, 00, 0), new DateTime(2011, 5, 18, 16, 00, 0), "EM250");
            var mgmtEnterpriseExam = new Exam(Guid.NewGuid(), new DateTime(2011, 5, 16, 9, 30, 0), new DateTime(2011, 5, 16, 11, 30, 0), "SH1");

            //Create modules
            var introToDBS = new Module(Guid.NewGuid(), 2010, Semester.SemesterTwo, "Introduction to Database Systems", "F27DB2", "");
            introToDBS.Lessons = new List<Lesson>() { introToDBSLesson1, introToDBSLesson2, introToDBSLesson3 };
            introToDBS.Exams = new List<Exam>() { introToDBSExam };
            introToDBS.Courseworks = new List<Coursework>() { introToDBSCoursework1, introToDBSCoursework2 };

            var introToComputerSystems = new Module(Guid.NewGuid(), 2010, Semester.SemesterTwo, "Introduction to Computer Systems", "F27CS2", "");
            introToComputerSystems.Lessons = new List<Lesson>() { introToComputerSystemsLesson1, introToComputerSystemsLesson2 };

            var technoInSociety = new Module(Guid.NewGuid(), 2010, Semester.SemesterTwo, "Technology in Society", "F27TS2", "");
            technoInSociety.Lessons = new List<Lesson>() { technoInSocietyLesson1, technoInSocietyLesson2 };
            technoInSociety.Courseworks = new List<Coursework>() { technoInSocietyCoursework1, technoInSocietyCoursework2, technoInSocietyCoursework3 };

            var mgmtEnterprise = new Module(Guid.NewGuid(), 2010, Semester.SemesterTwo, "Database Management Systems", "F28DM2", "");
            mgmtEnterprise.Lessons = new List<Lesson>() { mgmtEnterpriseLesson1 };
            mgmtEnterprise.Exams = new List<Exam>() { mgmtEnterpriseExam };

            //Create user - the username is what will be used for the user recognition
            var firstYear = new User(Guid.NewGuid(), "Fiona", "First", username, "Information Systems");
            firstYear.Modules = new List<Module>() { introToDBS, introToComputerSystems, technoInSociety, mgmtEnterprise };

            return firstYear;
        }

        private User CreateExample2ndYear(string username)
        {
            //Create Lessons
            //Note: new DateTime(2011, 3, 28, 9, 15, 0) = 28/3/2010 9:15.00
            var foundationMathsBLesson1 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 28, 11, 15, 0), new DateTime(2011, 3, 28, 12, 15, 0), "LT3");
            var foundationMathsBLesson2 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 31, 10, 15, 0), new DateTime(2011, 3, 31, 11, 15, 0), "LT1");
            var foundationMathsBLesson3 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 31, 11, 15, 0), new DateTime(2011, 3, 31, 12, 15, 0), "SR214");
            var foundationMathsBLesson4 = new Lesson(Guid.NewGuid(), new DateTime(2011, 4, 1, 13, 15, 0), new DateTime(2011, 4, 1, 14, 15, 0), "LT1");

            var softwareDesignLesson1 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 28, 15, 15, 0), new DateTime(2011, 3, 28, 16, 15, 0), "DB113");
            var softwareDesignLesson2 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 29, 15, 15, 0), new DateTime(2011, 3, 29, 16, 15, 0), "EM244");
            var softwareDesignLesson3 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 31, 12, 15, 0), new DateTime(2011, 3, 31, 13, 15, 0), "EM244");

            var programmingLangLesson1 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 29, 11, 15, 0), new DateTime(2011, 3, 29, 12, 15, 0), "EM183");
            var programmingLangLesson2 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 29, 12, 15, 0), new DateTime(2011, 3, 29, 13, 15, 0), "EM250");
            var programmingLangLesson3 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 30, 11, 15, 0), new DateTime(2011, 3, 30, 12, 15, 0), "EM336");
            var programmingLangLesson4 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 31, 15, 15, 0), new DateTime(2011, 3, 31, 16, 15, 0), "EM336");

            var dbmsLesson1 = new Lesson(Guid.NewGuid(), new DateTime(2011, 3, 30, 12, 15, 0), new DateTime(2011, 3, 30, 13, 15, 0), "EM182");
            var dbmsLesson2 = new Lesson(Guid.NewGuid(), new DateTime(2011, 4, 1, 10, 15, 0), new DateTime(2011, 4, 1, 11, 15, 0), "EM182");
            var dbmsLesson3 = new Lesson(Guid.NewGuid(), new DateTime(2011, 4, 1, 12, 15, 0), new DateTime(2011, 4, 1, 13, 15, 0), "DB114");

            //Create courseworks
            var softwareDesignCoursework1 = new Coursework(Guid.NewGuid(), "Software Design Coursework 1", "", new DateTime(), new DateTime(2011, 2, 28, 15, 0, 0));
            var softwareDesignCoursework2 = new Coursework(Guid.NewGuid(), "Software Design Coursework 2", "", new DateTime(), new DateTime(2011, 3, 21, 15, 0, 0));
            var dbmsCoursework = new Coursework(Guid.NewGuid(), "Database Management Coursework", "", new DateTime(), new DateTime(2011, 4, 1, 16, 30, 0));
            var programmingLanguagesCoursework = new Coursework(Guid.NewGuid(), "Database Management Coursework", "", new DateTime(), new DateTime(2011, 3, 30, 16, 30, 0));

            //Create exams
            var foundationMathsBExam = new Exam(Guid.NewGuid(), new DateTime(2011, 5, 20, 9, 30, 0), new DateTime(2011, 5, 20, 11, 30, 0), "SH1");
            var softwareDesignExam = new Exam(Guid.NewGuid(), new DateTime(2011, 5, 19, 9, 30, 0), new DateTime(2011, 5, 19, 11, 30, 0), "JWC2");
            var programmingLanguagesExam = new Exam(Guid.NewGuid(), new DateTime(2011, 5, 17, 14, 00, 0), new DateTime(2011, 5, 17, 16, 00, 0), "JWC2");
            var dbmsExam = new Exam(Guid.NewGuid(), new DateTime(2011, 5, 12, 9, 30, 0), new DateTime(2011, 5, 12, 11, 30, 0), "JWC2");

            //Create modules
            var foundationMathsB = new Module(Guid.NewGuid(), 2010, Semester.SemesterTwo, "Foundation Maths B", "F17SQ2", "");
            foundationMathsB.Lessons = new List<Lesson>() { foundationMathsBLesson1, foundationMathsBLesson2, foundationMathsBLesson3, foundationMathsBLesson4 };
            foundationMathsB.Exams = new List<Exam>() { foundationMathsBExam };
            
            var softwareDesign = new Module(Guid.NewGuid(), 2010, Semester.SemesterTwo, "Software Design", "F28SD2", "");
            softwareDesign.Lessons = new List<Lesson>() { softwareDesignLesson1, softwareDesignLesson2, softwareDesignLesson3 };
            softwareDesign.Exams = new List<Exam>() { softwareDesignExam };
            softwareDesign.Courseworks = new List<Coursework>() { softwareDesignCoursework1, softwareDesignCoursework2 };

            var programmingLanguages = new Module(Guid.NewGuid(), 2010, Semester.SemesterTwo, "Programming Languages", "F28PL2", "");
            programmingLanguages.Lessons = new List<Lesson>() { programmingLangLesson1, programmingLangLesson2, programmingLangLesson3, programmingLangLesson4 };
            programmingLanguages.Exams = new List<Exam>() { programmingLanguagesExam };
            programmingLanguages.Courseworks = new List<Coursework>() { programmingLanguagesCoursework };
            
            var dbms = new Module(Guid.NewGuid(), 2010, Semester.SemesterTwo, "Database Management Systems", "F28DM2", "");
            dbms.Lessons = new List<Lesson>() { dbmsLesson1, dbmsLesson2, dbmsLesson3 };
            dbms.Exams = new List<Exam>() { dbmsExam };
            dbms.Courseworks = new List<Coursework>() { dbmsCoursework };

            //Create user - the username is what will be used for the user recognition
            var secondYear = new User(Guid.NewGuid(), "Simon", "Second", username, "Computer Science");
            secondYear.Modules = new List<Module>() { foundationMathsB, softwareDesign, programmingLanguages, dbms };

            return secondYear;
        }

        #endregion
    }
}
